package com.mediacloud.app.newsmodule.activity.microlive;

import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;

import com.mediacloud.app.assembly.util.FunKt;
import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig;

/**
 * Created by x on 2018/1/24.
 */

public class SBZGNineGridHolder extends RecyclerView.ViewHolder implements ViewTreeObserver.OnPreDrawListener {
    ImageView imageViewX;
    public SBZGNineGridHolder(View itemView)
    {
        super(itemView);
        imageViewX= itemView.findViewById(R.id.imageView);
    }

    public void updateData(String url)
    {
        imageViewX.getViewTreeObserver().addOnPreDrawListener(this);
        imageViewX.setBackgroundColor(AppFactoryGlobalConfig.getDefaultImagLoadBackground());
        FunKt.load(imageViewX,url);
    }

    @Override
    public boolean onPreDraw()
    {
        int width = imageViewX.getWidth();
        int height = (int) (width / (16.0 / 9.0));
        imageViewX.getLayoutParams().height=height;
        imageViewX.getLayoutParams();
        imageViewX.requestLayout();
        imageViewX.getViewTreeObserver().removeOnPreDrawListener(this);
        return true;
    }
}